
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表格</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/static/image/code.png">
</head>
<body class="body">

<div class="tab-top">
  <a class="layui-btn site-demo-active layui-btn-sm" data-type="tabAdd" id="adduser" data-href="{:url('admin/User/add')}"><i class="layui-icon">&#xe608;</i>添加管理员</a>

<div class="search">
  <form class="layui-form" action="">
        <div class="layui-input-inline">
        <select name="search" lay-verify="required" class="search-name" lay-search="">
          <option value="user" {$search=='user' ? 'selected=""' : ''}>用户名</option>
          <option value="nickname" {$search=='nickname' ? 'selected=""' : ''}>简  称</option>
          <option value="email" {$search=='email' ? 'selected=""' : ''}>邮  箱</option>
        </select>
      </div>
  <div class="layui-inline">
    <input class="layui-input layui-input-sm" name="val" placeholder="请输入用户名" id="search-elm" autocomplete="off" value="{$val}">
  </div>
  <button class="layui-btn site-demo-active layui-btn-sm search-btn" data-type="reload">搜索</button>
</form>
</div>

</div>



<div class="layui-form">
<table class="layui-table" lay-filter="parse-table-demo" lay-data="{height:'full-120',url:'{:url('admin/user/ajaxlist',\Request::param())}', page:true, id:'test',limit:'{:config('webconfig.page')}'}">
    <thead>
      <tr>
        <th lay-data="{type:'checkbox'}"></th>
        <th lay-data="{field:'id', width:50,sort:true}">ID</th>
        <th lay-data="{field:'user_name', width:150}">用户名</th>
        <th lay-data="{field:'sex', width:60, align:'center'}">性别</th>
        <th lay-data="{field:'nickname', width:130}">简称</th>
        <th lay-data="{field:'login_ip', width:130}">IP</th>
        <th lay-data="{field:'update_time', width:150}">登录时间</th>
        <th lay-data="{field:'authtitle', width:200}">权限</th>
        <th lay-data="{field:'remark', minwidth:50,edit: 'text'}">备注</th>
        <th lay-data="{field:'status', width:100, toolbar: '#statusTpl'}">状态</th>
        <th lay-data="{fixed: 'right', width:158, align:'center', toolbar: '#barDemo'}">操作</th>
      </tr> 
    </thead>
  </table>
</div>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="auth">权限</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="statusTpl">
  <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="禁|否" lay-filter="lockstatus" {{ d.status == 0 ? 'checked' : '' }}>
</script>

<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script src="__ADMIN__/js/comm.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'table','admin'], function() {
  var $ = layui.jquery,
    form = layui.form,
    table = layui.table,
    admin = layui.admin;

  //监听单元格编辑
  table.on('edit(parse-table-demo)', function(obj) {
    var value = obj.value //得到修改后的值
      ,data = obj.data; //得到所在行所有键值
    $.post('{:url('admin/User/quickedit')}', {
        id: data.id,
        remark: value
      },
      function(data) {
        if (data) {
          layer.msg(data.msg);
        }
      });

  });

  //监听工具条
  table.on('tool(parse-table-demo)', function(obj) {
    var data = obj.data;
    if (obj.event === 'auth') {
      url = "{:url('admin/User/auth')}?id="+data.id;
      admin.actAuth(url,function(){ //判断权限
        layer.open({
          title: "用户权限修改",
          type: 2,
          area: ['450px', '400px'],
          fixed: false, //不固定
          maxmin: true,
          content: url
        });
      });


    } else if (obj.event === 'del') {
      layer.confirm('真的删除行么', function(index) {
        //window.location.href = '{:url('delete','',false)}/id/' + data.id;
        $.get("{:url('admin/User/delete')}?id=" + data.id,function(data){
        if (data.code == 1) {
          layer.msg(data.msg);
          obj.del();
        }else{
          layer.msg(data.msg);
        }
        layer.close(index);
        });

      });
    } else if (obj.event === 'edit') {
      url = "{:url('admin/User/edit')}?id=" + data.id;
      admin.actAuth(url,function(){
        layer.open({
          title: "用户信息修改",
          type: 2,
          area: ['550px', '620px'],
          fixed: false, //不固定
          maxmin: true,
          content: url
        });
      });
    }
  });

  //监听锁定操作
  form.on('switch(lockstatus)', function(obj) {
    if (obj.elem.checked === true) {
      statusval = 0;
    } else {
      statusval = 1;
    }
    $.post('{:url('admin/User/quickedit')}', {
        id: this.value,
        status: statusval
      },
      function(data) {
        if (data) {
          layer.tips(data.msg, obj.othis);
        }
      });
  });

$('#adduser').click(function(){

      layer.open({
        title: "添加用户信息",
        type: 2,
        area: ['550px', '620px'],
        fixed: false, //不固定
        maxmin: true,
        content: $(this).attr('data-href')
      });
});

  // $('.search-btn').on('click', function(){
  //   //$('#search-elm').val();
  //   location.href = '{:url('admin/User/index')}?'+$('.search-name').val()+'='+$('#search-elm').val();
  //   //active[type] ? active[type].call(this) : '';
  //   return false;
  // });
});
</script>
</body>
</html>